package com.fzy.silntgym.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.EditText;
import android.widget.TabHost;
import android.widget.Toast;

import com.fzy.silntgym.R;
import com.fzy.silntgym.application.UserAgent;

public class TopicActivity extends AppCompatActivity {
    private long exitTime=0L;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_topic);
        EditText title = (EditText)findViewById(R.id.tltie_send);
        EditText content = (EditText)findViewById(R.id.content_send);
        if (title != null && content != null) {
            title.setText(UserAgent.getTitle_send());
            content.setText(UserAgent.getContent_send());
        }

    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK
                && event.getAction() == KeyEvent.ACTION_DOWN) {
            if ((System.currentTimeMillis() - exitTime) > 2000) {
                Toast.makeText(getApplicationContext(), "再按一次返回",
                        Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
            } else {
                EditText title = (EditText)findViewById(R.id.tltie_send);
                EditText content = (EditText)findViewById(R.id.content_send);
                UserAgent.setTitle_send(title.getText().toString());
                UserAgent.setContent_send(content.getText().toString());
                Toast.makeText(getApplicationContext(),"未发送的信息已保存到草稿", Toast.LENGTH_LONG).show();
                finish();
            }
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
